home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / cde.idb / usr / dt / share / examples / dtksh / SessionTest.z / SessionTest
Encoding:
Text File  |  2003-11-18  |  5.0 KB  |  160 lines

  1. #! /usr/dt/bin/dtksh
  2. #
  3. # SessionTest
  4. #
  5. # Copyright 2000, Silicon Graphics, Inc.
  6. # ALL RIGHTS RESERVED
  7. # UNPUBLISHED -- Rights reserved under the copyright laws of the United
  8. # States.   Use of a copyright notice is precautionary only and does not
  9. # imply publication or disclosure.
  10. #
  11. # U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  12. # Use, duplication or disclosure by the Government is subject to restrictions
  13. # as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  14. # in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  15. # in similar or successor clauses in the FAR, or the DOD or NASA FAR
  16. # Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  17. # 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  18. #
  19. # THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  20. # INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  21. # DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  22. # PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  23. # GRAPHICS, INC.
  24. #
  25. ##########################################################################
  26. #  (c) Copyright 1993, 1994 Hewlett-Packard Company    
  27. #  (c) Copyright 1993, 1994 International Business Machines Corp.
  28. #  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  29. #  (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
  30. #      Novell, Inc.
  31. ##########################################################################
  32.  
  33.  
  34. #
  35. # This sample shell script demonstrates the steps necessary for tying into
  36. # session management.  To run, simply run this script, and then save the
  37. # current session.  When the session is restored, this script should again
  38. # restore to its previous state.
  39. #
  40.  
  41.  
  42. # This function is invoked when the user attempts to save the current session.
  43. # It will save off its state information (whether it is iconified, and the
  44. # list of workspaces it occupies) into a session file, and then tell the
  45. # session manager how to reinvoke it when the session is restored.
  46. SessionCallback()
  47. {
  48. #  Get the name of our session file
  49.    if DtSessionSavePath $TOPLEVEL PATH SAVEFILE; then
  50.       exec 9>$PATH
  51.  
  52. #     Save our iconification state
  53.       if DtShellIsIconified $TOPLEVEL ; then
  54.          print -u9 'Iconified'
  55.       else
  56.          print -u9 'Deiconified'
  57.       fi
  58.  
  59. #     Save the list of workspace we occupy
  60.       if DtWsmGetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
  61.                                     $(XtWindow "-" $TOPLEVEL) \
  62.                                     CURRENT_WS_LIST ;
  63.       then
  64.          oldIFS=$IFS
  65.          IFS=","
  66.          for item in $CURRENT_WS_LIST; 
  67.          do
  68.             XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $item
  69.             print -u9 $NAME
  70.          done
  71.          IFS=$oldIFS
  72.       fi
  73.  
  74.       exec 9<&-
  75.  
  76. #     Tell the session manager how to restart us
  77.       DtSetStartupCommand $TOPLEVEL \
  78.            "/usr/dt/share/examples/dtksh/SessionTest $SAVEFILE"
  79.    else
  80.       echo "DtSessionSavePath FAILED!!"
  81.       exit -3
  82.    fi
  83. }
  84.  
  85.  
  86. # This function is invoked when we are restarted at session restore time.
  87. # It is passed the name of the session file as $1.  It will extract our
  88. # session information from the session file, and will restore our state
  89. # accordingly.
  90. RestoreSession()
  91. {
  92. #  Get the full path of our session file
  93.    if DtSessionRestorePath $TOPLEVEL PATH $1; then
  94.       exec 9<$PATH
  95.       read -u9 ICONIFY
  96.  
  97. #     Restore our iconification state
  98.       case $ICONIFY in
  99.          Iconified) DtSetIconifyHint $TOPLEVEL True;;
  100.          *)         DtSetIconifyHint $TOPLEVEL False;;
  101.       esac
  102.  
  103. #     Place us into the indicated set of workspaces
  104.       WS_LIST=""
  105.       while read -u9 NAME
  106.       do
  107.          XmInternAtom ATOM $(XtDisplay "-" $TOPLEVEL) $NAME False
  108.          if [ ${#WS_LIST} -gt 0 ]; then
  109.             WS_LIST=$WS_LIST,$ATOM
  110.          else
  111.             WS_LIST=$ATOM
  112.          fi
  113.       done
  114.  
  115.       DtWsmSetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
  116.                                  $(XtWindow "-" $TOPLEVEL) \
  117.                                  $WS_LIST
  118.  
  119.       exec 9<&-
  120.    else
  121.       echo "DtSessionRestorePath FAILED!!"
  122.       exit -3
  123.    fi
  124. }
  125.  
  126.  
  127.  
  128. ######################### Create the Main UI #################################
  129.  
  130. XtInitialize TOPLEVEL wmProtTest WmProtTest "$0" "$@"
  131.  
  132. XtCreateManagedWidget DA da XmDrawingArea $TOPLEVEL
  133. XtSetValues $DA height:200 width:200
  134.  
  135. XmInternAtom SAVE_SESSION_ATOM $(XtDisplay "-" $TOPLEVEL) "WM_SAVE_YOURSELF" False
  136.  
  137.  
  138. # If we are invoked with any command line parameters, then we will assume
  139. # that it is the name of our session file, and will restore to the indicated
  140. # state.
  141. if (( $# > 0))
  142. then
  143.    XtSetValues $TOPLEVEL mappedWhenManaged:False
  144.    XtRealizeWidget $TOPLEVEL
  145.    XSync $(XtDisplay "-" $TOPLEVEL) False
  146.    RestoreSession $1
  147.    XtSetValues $TOPLEVEL mappedWhenManaged:True
  148.    XtPopup $TOPLEVEL GrabNone
  149. else
  150.    XtRealizeWidget $TOPLEVEL
  151.    XSync $(XtDisplay "-" $TOPLEVEL) False
  152. fi
  153.  
  154. # Register our interest in participating in session management.
  155. XmAddWMProtocols $TOPLEVEL $SAVE_SESSION_ATOM
  156. XmAddWMProtocolCallback $TOPLEVEL $SAVE_SESSION_ATOM SessionCallback
  157.  
  158. XtMainLoop
  159.